﻿package gear.utils {
	import gear.log4a.LogError;

	import flash.utils.Dictionary;
	import flash.utils.Proxy;
	import flash.utils.flash_proxy;

	/**
	 * Global Object for Game
	 * 
	 * @author bright
	 * @version 20100929
	 */
	public dynamic class Global extends Proxy {
		private static var _creating : Boolean = false;
		private static var _instance : Global;
		private var _list : Dictionary;

		override flash_proxy function callProperty(methodName : *, ...args) : * {
			return _list[methodName].apply(null, args);
		}

		override flash_proxy function getProperty(name : *) : * {
			return _list[name];
		}

		override flash_proxy function setProperty(name : *, value : *) : void {
			_list[name] = value;
		}

		public function Global() {
			if (!_creating) {
				throw (new LogError("Class cannot be instantiated.Use Global.instance instead."));
			}
			_list = new Dictionary();
		}

		public static function get instance() : Global {
			if (_instance == null) {
				_creating = true;
				_instance = new Global();
				_creating = false;
			}
			return _instance;
		}
	}
}
